package com.cysoft.starter.repeat.core.configuration;

import com.cysoft.starter.repeat.config.RepeatAutoConfiguration;
import com.cysoft.starter.repeat.core.aspect.RepeatAspect;
import com.cysoft.starter.repeat.core.properties.RepeatSubmitProperties;
import com.cysoft.starter.repeat.core.validata.impl.CaffeineRepeatValidata;
import com.cysoft.starter.repeat.core.validata.impl.RedisRepeatValidata;
import com.github.benmanes.caffeine.cache.LoadingCache;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author 玖零
 * @version V0.0.1
 * @project cysoft-spring-boot-starter-repeat
 * @package com.cysoft.starter.repeat.core.configuration
 * @date 2025-03-02 15:09
 * @desc
 */
@Slf4j
@Configuration
@ConditionalOnBean(name = "caffeineConfiguration")
@AutoConfigureAfter(RepeatAutoConfiguration.class)
public class CaffeineRepeatConfiguration {

    /**
     * 防重复提交配置信息
     */
    private final RepeatSubmitProperties repeatSubmitProperties;

    /**
     * caffeine放重复提交配置 构造方法
     * @param repeatSubmitProperties
     */
    public CaffeineRepeatConfiguration(RepeatSubmitProperties repeatSubmitProperties) {
        log.info("初始化CaffeineRepeatConfiguration，注入防重复提交配置信息");
        this.repeatSubmitProperties = repeatSubmitProperties;
    }


    @Bean
    public RepeatAspect caffeineRepeatAspect(){
        log.info("******************开始初始化caffeineRepeatAspect******************");
        log.info("开始构建caffeine防重复提交切面");
        RepeatAspect repeatAspect = new RepeatAspect(new CaffeineRepeatValidata(), repeatSubmitProperties);
        log.info("caffeine防重复提交切面构建成功，切面对象: {}", repeatAspect);
        return repeatAspect;
    }



}
